#include <iostream>
#include <algorithm>

using namespace std;
typedef long long LL;

const int N = 2e5 + 10;
int a[N];
LL s[N];
int n;
 
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	LL ans = a[1];
	LL prevmin = 0;
	for(int i = 1; i <= n; i++)
	{
		s[i] = s[i - 1] + a[i];
	}
	
	for(int i = 1; i <= n; i++)
	{
		ans = max(ans, s[i] - prevmin);
		prevmin = min(prevmin, s[i]);
	
	}
	
	cout << ans << endl;
	
	return 0;
 } 
